<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('dashBoard.no19')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('dashBoard.no12')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('dashBoard.no16')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- -------------搜索查询栏------------------------ -->
    <search 
      :searchData="searchData" 
      @search="search" 
      :searchRight="true"
    ></search>

    <!-- -------------表单显示栏------------------------ -->
    <div class="table" >
      <template>
        <el-table :data="tableData" size="small" stripe >
          <el-table-column align="center" prop="id" :label="$t('public.backMoneyId')">
          </el-table-column>
          <el-table-column align="center" prop="orderId" :label="$t('public.orderId')">
          </el-table-column>
          <el-table-column align="center" prop="userId" :label="$t('public.userId')">
          </el-table-column>
          <el-table-column align="center" prop="userName" :label="$t('public.name')">
          </el-table-column>
          <el-table-column align="center" prop="btId" :label="$t('finance.dealCode')">
          </el-table-column>
          <el-table-column align="center" prop="repaymentNo" :label="$t('finance.repaymentNo')">
          </el-table-column>
          <el-table-column align="center" prop="phone" :label="$t('public.no18')">
          </el-table-column>
          <el-table-column align="center" prop="loanAmount" :label="$t('public.no54')">
            <template slot-scope="scope">
              <span>{{$store.state.common.id_currency}}{{$store.getters.moneySplit(scope.row.loanAmount)}}{{$store.state.common.vi_currency}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="productPeriod" :label="$t('public.no31')">
          </el-table-column>
          <el-table-column align="center" prop="overdueInterestRate" :label="$t('proManage.overdueInterest')">
            <template slot-scope="scope">
              <span>{{$store.getters.twoPoint(scope.row.overdueInterestRate)}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="returnMoney" :label="$t('public.no27')">
            <template slot-scope="scope">
              <span>{{$store.state.common.id_currency}}{{$store.getters.moneySplit(scope.row.returnMoney)}}{{$store.state.common.vi_currency}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="refundAmount" :label="$t('public.no65')">
            <template slot-scope="scope">
              <span>{{$store.state.common.id_currency}}{{$store.getters.moneySplit(scope.row.refundAmount)}}{{$store.state.common.vi_currency}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="applyTime" :label="$t('public.CreateDate')" width="86">
          </el-table-column>
          <el-table-column align="center" prop="lastRefundTime" :label="$t('public.backMoneyDate')" width="86">
          </el-table-column>
          <el-table-column align="center" prop="overdueDays" :label="$t('public.no43')">
            <template slot-scope="scope">
              <span>{{scope.row.overdueDays>0?$t('operationDetail.no11'):$t('operationDetail.no12')}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="status" :label="$t('public.no22')">
            <template slot-scope="scope">
              <span>{{$t($store.getters.backMoneyLogStatus(scope.row.status))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="thirdChannel" :label="$t('finance.channel')"></el-table-column>
          <el-table-column align="center" prop="payType" :label="$t('finance.payType')">
          </el-table-column>
          <el-table-column align="center" prop="partnerName" :label="$t('merchantList.no1')"></el-table-column>
          <!-- <el-table-column align="center" prop="status" label="APK"></el-table-column> -->
          <el-table-column align="center" prop="remark" :label="$t('public.no37')"></el-table-column>
        </el-table>
      </template>
    </div>

    <!-- ------------  分页显示栏  ------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>

    <div class="foot"></div>

  </div>
</template>
<script>
import getMerchant from 'src/mixins/getMerchant.js';
import getPayChannel from 'src/mixins/getPayChannel.js';//获取下拉通道
export default {
  name: 'backLogList',
  mixins: [getMerchant,getPayChannel],
  data () {
    const searchData=[
      {
        type: 'input',
        label: 'finance.repaymentNo',
        attr: 'repaymentNo',
        value: ''
      },
      {
        type: 'input',
        label: 'public.orderId',
        attr: 'orderId',
        value: ''
      },
      {
        type: 'input',
        label: 'public.userId',
        attr: 'userId',
        value: ''
      },
      {//通道
        type: 'select',
        label: 'finance.channel',
        attr: 'thirdChannel',
        option: [],
        value: '',
        langFlag: false,
      },
      {//逾期
        type: 'select',
        label: 'public.no53',
        attr: 'isOverDue',
        option: this.$store.state.options.isOverdue_option,
        value: '',
        langFlag: true,
      },
      {
        type: 'rangePicker',
        label: 'public.CreateDate',
        attr: 'createTime',
        value: [],
      },
      {
        type: 'rangePicker',
        label: 'public.backMoneyDate',
        attr: 'paySuccess',
        value: [],
      },
      {
        type: 'select',
        label: 'public.no22',
        attr: 'status',
        option: this.$store.state.options.backMoneyLog_select,
        value: '',
        langFlag: true,
      },
      {
        type: 'select',
        label: 'merchantList.no1',
        attr: 'partnerId',
        option: [],
        value: '',
        langFlag: false,
      },
    ]
    return {
      loadFlag: true,
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchTime1: [], // 订单创建时间数组
      searchTime2: [], // 申请成功时间数组
      formInline: {},// 用户查询信息数据对应字段
      searchData:searchData,
      options1: this.$store.state.options.backMoneyType_option_vi, // 还款方式
      options2: this.$store.state.options.backMoney_backType_vi, // 通道
      options3: this.$store.state.options.backMoneyLog_select, // 状态下拉选框信息
      options4: this.$store.state.options.isOverdue_option, // 逾期状态下拉选框信息
      options5: this.$store.state.options.couponType_option,// 优惠券类型下拉选框信息
      tableData: [], // 用户信息数据模拟
    }
  },
  methods: {
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.getTableData();
    },
    search (search) { // 查询按钮点击操作
      this.formInline = {
        orderId: search.orderId,
        orderNo:search.orderNo,
        repaymentNo: search.repaymentNo,
        payType:search.payType,
        thirdChannel: search.thirdChannel,
        isOverDue: search.isOverDue,
        createTimeBegin: search.createTime?search.createTime[0]:'',
        createTimeEnd: search.createTime?search.createTime[1]:'',
        paySuccessBegin: search.paySuccess?search.paySuccess[0]:'',
        paySuccessEnd: search.paySuccess?search.paySuccess[1]:'',
        status: search.status,
        couponType: search.couponType,
        appName: search.appName,
        appPackage:search.appPackage,
        partnerId:search.partnerId,
      }
      this.pagination.current = 1;
      this.getTableData();
    },
    getTableData () { // 列表数据获取
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.pay_loan_repayment, option).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.pagination.total = res.data.total;
        }else{
          this.$globalMsg.error(res.message)
        }
        this.loadFlag = false;
      })
    },
    getChannelData(){//获取借款放款渠道下拉框数据
      let option = {
        param:{
          channelType: 4
        }
      }
      this.$axios.post(this.$action.channel_list, option).then(res => {
        if (res.code == 200) {
          let arr = []
          res.data.forEach(item=>{
            arr.push({value:item.channelName,label:item.channelName})
          })
          this.searchData.filter(value=>value.attr=='thirdChannel')[0].option = arr
				}
      })
    },
  },
  watch: {
    searchTime1 () {
      if (this.searchTime1) {
        this.formInline.createTimeBegin = this.$store.getters.yyyy_m_d(this.searchTime1[0]);
        this.formInline.createTimeEnd = this.$store.getters.yyyy_m_d(this.searchTime1[1]);
      } else {
        this.formInline.createTimeBegin = '';
        this.formInline.createTimeEnd = '';
      }
    },
    searchTime2 () {
      if (this.searchTime2) {
        this.formInline.paySuccessBegin = this.$store.getters.yyyy_m_d(this.searchTime2[0]);
        this.formInline.paySuccessEnd = this.$store.getters.yyyy_m_d(this.searchTime2[1]);
      } else {
        this.formInline.paySuccessBegin = '';
        this.formInline.paySuccessEnd = '';
      }
    }
  },
  mounted () {
    this.getTableData();
    this.getMerchant().then(data=>{
      this.searchData.filter(value=>value.attr=='partnerId')[0].option = data
    })
    this.getChannelData()
    
  }
}
</script>
<style scoped lang="scss">

</style>
